# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：get_stock_point.py
#日期：2020-06-29
#备注：将推中长线股票买卖点存入到数据库   
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

from pacong.stock.stock_config import db,cursor
from pycacho.cachobase.logger import Logger


logger = Logger("get_stock_point").get_log()


stock_info = [['603078','江化微','光刻胶','湿电子化学品',43.0,46.6,'中线'],
        ['603686','龙马环卫','节能环保','环卫装备行业',22.9,25.4,'中线'],
        ['601698','中国卫通','天基互联','广播卫星',17.8,19.6,'中线'],
        ['002950','奥美医疗','医疗器械','医疗器械',23.8,27.6,'中线'],
        ['603056','德邦股份','交运物流','物流快递',13.5,14.9,'中线'],
        ['603890','春秋电子','消费电子','笔记本电脑',15.6,17.4,'中线'],
        ['600966','博汇纸业','造纸印刷','造纸行业',8.88,10.21,'中线'],
        ['600804','鹏博士','电信运营', '互联网宽带', 8.0,9.0,'中线'],
        ['002398', '垒知集团', '工程建设', '建筑科研机构、外加剂新材料', 10.2, 12.2, '中线'],
        ['002332', '仙琚药业', '医疗行业', '地塞米松', 16.0, 17.7, '中线'],
        ['603533', '掌阅科技', '文化传媒', '在线阅读', 36.0, 40.1, '中线'],
        ['600216', '浙江医药', '医药制造', '维生素', 19.1, 20.17, '中线'],
        ['603283', '赛腾股份', '消费电子', '无线耳机', 49.8, 56.0, '中线'],
        ['002292', '奥飞娱乐', '网络游戏', '全年龄段IP矩阵', 8.15, 9, '中线'],
        ['603113', '金能科技', '煤炭采选', '煤化工', 11.5, 12.15, '中线'],
        ['002734', '利民股份', '农药兽药', '蝗虫防治', 14.1, 21.0, '中线'],
        ['603787', '新日股份', '交运设备', '电动自行车、美团大订单', 17.3, 19.8, '中线'],
        ['002385', '大北农', '农业种植', '转基因', 8.9, 9.7, '中线'],
        ['600609', '金杯汽车', '汽车行业', '汽车制造', 6.0, 6.6, '中线'],
        ['002401', '中远海科', '智慧城市', '软件服务、业绩大增', 15.0, 16.47, '中线'],
        ['600329', '中新药业', '医药制造', '基因测序', 16.3, 18.05, '中线'],
        ['002127', '南极电商', '电商概念', '网红直播', 20.1, 22.66, '中线'],
        ['002706', '良信电器', '输电电气', '低压电器', 15.25, 17.02, '中线'],
        ['002600', '领益制造', '消费电子', '低压电器', 10.15, 11.15, '中线'],
        ['000636', '风华高科', '电子元件', 'MLCC', 27.6, 31.15, '中线'],
        ['002402', '和而泰', '物联网', '智能控制器', 15.4, 16.5, '中线'],
        ['002481', '双塔食品', '食品饮料', '人造肉', 17.1, 18.68, '中线'],
        ['603239', '浙江仙通', '汽车行业', '汽车零部件', 13.75, 14.84, '中线'],
        ['002666', '德联集团', '汽车行业', '特拉斯', 13.75, 14.84, '中线'],
        ['002707', '众信旅游', '在线旅游', '免税概念', 7.05, 8.02, '中线'],
        ['002240', '威华股份', '新材料', '锂电池', 12.5, 18, '中线'],
        ['601865', '福莱特', '玻璃陶瓷', '特种玻璃', 17.1, 21, '中线'],
        ['002028', '思源电气', '输电电气', '特高压', 21.05, 22.38, '中线'],
        ['002581', '未名医药', '医药制造', '生物疫苗', 25.5, 30.0, '中线'],
        ['002541', '鸿路钢构', '水泥建材', '钢结构业务', 24.85, 29.77, '中线'],
        ['600984', '建设机械', '机械行业', '工程机械', 20.75, 25.62, '中线'],
        ['600197', '伊力特', '酿酒行业', '新疆白酒', 18.65, 21.0, '中线'],
        ['600532', '宏达矿业', '钢铁行业', '黑色金属矿采', 11.6, 21.0, '中线'],
        ['002375', '亚夏股份', '装修装饰', '装配式装修龙头', 9.35, 10.75, '中线'],
        ['600988', '赤峰黄金', '贵金属', '黄金', 11.15, 12.34, '中线'],
        ['603700', '宁水集团', '仪表仪器', '智能水表', 29.65, 32.35, '中线'],
        ['002539', '云图控股', '化肥行业', '电子竞技', 6.7, 7.2, '中线'],
        ['002698', '博实股份', '智能机器', '大型智能成套装备', 12.15, 14.35, '中线'],
        ['002129', '中环股份', '太阳能', '半导体硅片龙头', 20.4, 30.0, '中线'],
        ['600459', '贵研铂业', '贵金属', '国六标准、业绩大增', 26.1, 35.5, '中线'],
        ['000951', '中国重汽', '汽车行业', '重型卡车', 29.15, 35.0, '中线'],
        ]

def createTable():
    sql1 = 'drop table if exists stock_point;'
    sql2 = 'create table stock_point (stock_no VARCHAR(10),stock_name VARCHAR(10),stock_theme VARCHAR(100),stock_detail VARCHAR(100),point_min float,point_max float,point_type VARCHAR(10),create_time datetime,PRIMARY KEY (stock_no));'
    #cursor.execute(sql1)
    cursor.execute(sql2)

def get_stock_info():
    for data in stock_info:
        stock_no = data[0]
        stock_name = data[1]
        stock_theme = data[2]
        stock_detail = data[3]
        point_min = data[4]
        point_max = data[5]
        point_type = data[6]
        stock_to_mysql(stock_no, stock_name, stock_theme,stock_detail,point_min,point_max,point_type)


# 将股票买卖点信息存入到数据库
def stock_to_mysql(stock_no, stock_name, stock_theme,stock_detail,point_min,point_max,point_type):
    sql = "insert into stock_point (stock_no, stock_name, stock_theme,stock_detail,point_min,point_max,point_type,create_time) values ('%s','%s','%s','%s','%s','%s','%s',now() );" \
          % (stock_no, stock_name, stock_theme,stock_detail,point_min,point_max,point_type)
    try:
        cursor.execute(sql)
    except Exception as e:
        db.rollback()
        print(str(e))
    else:
        db.commit()
        logger.info('%s股票买卖点信息插入成功！',stock_no)


if __name__ == '__main__':
    #createTable()
    get_stock_info()
